# 定义要替换的旧模块名和新模块名
$OLD_MODULE = "github.com/yourusername/user-crud"
$NEW_MODULE = "crud-go-projects/user-crud"

# 设置默认编码为 UTF-8
$PSDefaultParameterValues['*:Encoding'] = 'utf8'

# 查找所有 .go 文件并替换内容
Get-ChildItem -Recurse -Filter "*.go" | ForEach-Object {
    Write-Host "Processing file: $($_.FullName)"
    try {
        # 使用 UTF-8 无 BOM 编码读取文件
        $content = [System.IO.File]::ReadAllText($_.FullName, [System.Text.Encoding]::UTF8)
        $content = $content -replace [regex]::Escape($OLD_MODULE), $NEW_MODULE
        # 使用 UTF-8 无 BOM 编码写入文件
        [System.IO.File]::WriteAllText($_.FullName, $content, [System.Text.Encoding]::UTF8)
    } catch {
        Write-Error "Error processing file $($_.FullName): $_"
    }
} 